/*
 *  $Id$
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Serialization;
using Ragima.Languages;

namespace Ragima.Serialization {
    [TypeInfo(typeof(Language))]
    public class LanguageTypeInfo : TypeInfo<Language> {
        public override bool CanInlineToList {
            get { return true; }
        }

        public override Language Clone(Language value) {
            return value;
        }

        public override bool Equals(Language a, Language b) {
            if (a == b)
                return true;
            if (a == null || b == null)
                return false;
            return a.LangCode == b.LangCode;
        }

        public override bool IsNull(Language value) {
            return value == null;
        }

        public override Language ConvertFromString(string value) {
            return Language.AllLanguages.GetLanguage(value);
        }

        public override string ConvertToString(Language value) {
            return value.LangCode;
        }
    }
}
